<template>
  <a-modal v-model="visible"   :title="title"  @cancel='cancel' @ok='sure'>
    <a-form-model :model="qx" :label-col="{span :4 }" :wrapper-col="{ span: 20 }" style="margin-top: 20px">
      <a-form-model-item label="污染大类" required>
        <a-select
          placeholder="请选择污染大类"
          v-model="qx.polluteId">
          <a-select-option
            v-for="(item,index) in polluteList"
            :key="index"
            :value="item.polluteId"
          >
            {{ item.polluteName}}
          </a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="去向单位" required>
        <a-input v-model="qx.qx"/>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
import EpaSortService from '@/myService/EpaSortService'
export default {
  name: 'AddQxModal',
  data(){
    return{
      visible:false,
      title:'',
      polluteList:[],
      qx:{
        polluteId:undefined,
        qx:null
      },
      flag:false,
    }
  },
  created() {

  },
  methods: {
    open() {
      this.qx.qx=undefined
      this.visible=true;
      this.loading();
    },
    sure(){
      if(this.qx.polluteId == undefined || this.qx.qx == null){
        this.$message.error("内容不能为空")
      }else{
        EpaSortService.addQx(this.qx).then((res)=>{
          if(res.result===1){
            this.$message.success("创建成功")
            this.visible=false
          }else {
            this.$message.error("创建失败")
          }
        })
      }
      console.log(this.qx)
      this.$emit('loading')
    },
    cancel(){
      this.visible=false
    },
    loading(){
      console.log("dsdsd")
      EpaSortService.getPolluteList().then((res)=>{
        console.log(res)
        this.polluteList=res.result;
        console.log(this.polluteList)
      })
    }
  }
}
</script>

<style scoped>

</style>